

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
  <title>CFR714(Div. 2)2021.04.12 - violet apricity</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.4.0/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.9","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>violet apricity</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="CFR714(Div. 2)2021.04.12">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-04-16 10:31" pubdate>
        2021年4月16日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.1k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      33
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">CFR714(Div. 2)2021.04.12</h1>
            
            <div class="markdown-body">
              <p>链接：<a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513">#714(div.2)</a>.<br>开始记录cf的比赛，这是第一场。还不熟悉md格式，凑合写。<br>由于现在菜的很，div123只能过A，不过为了养成好习惯，还是写一 写。<del>（一题也行啊）</del> </p>
<h1 id="A-Array-and-Peaks（思维-构造）"><a href="#A-Array-and-Peaks（思维-构造）" class="headerlink" title="A. Array and Peaks（思维+构造）"></a>A. Array and Peaks（思维+构造）</h1><p><a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513/problem/A">https://codeforces.com/contest/1513/problem/A</a><br>链接: <a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513/problem/A">Array and Peaks</a>.<br>题意：给出整数n和k，将数字1~n排除某个序列使之出现k个峰。其中峰指该值比左右值都大。注意峰不能在首尾即前后必须有数字。<br>很简单的思维题。<br>官方题解：<br><img src="https://img-blog.csdnimg.cn/20210412111625366.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>显然峰值先考虑大到小，每隔一位就放入一个峰值然后将其减1作为下一个峰值。那么当峰值数大于总数的一半即k*2&gt;n将有峰值放不下也就是无解。<br>可以先判断有误解，再输出答案。<br>我当时比赛的代码：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs c++">        <span class="hljs-comment">// violet apricity</span><br><span class="hljs-comment">// Do all I can do.Do good to be good.</span><br> <br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;cstring&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;string&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;algorithm&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;vector&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;math.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;map&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;sstream&gt;</span></span><br> <br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> STD using namespace std;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ll long long</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> db double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ldb long double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> IOS std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> MAX 88888888</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> INF 0x3f</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> r0 return 0;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> SYP system(<span class="hljs-meta-string">&quot;pause&quot;</span>);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> endl <span class="hljs-meta-string">&#x27;\n&#x27;</span></span><br> <br>STD<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> maxn=<span class="hljs-number">105</span>;<br><span class="hljs-keyword">int</span> re[maxn];<br><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;=<span class="hljs-number">100</span>;i++)re[i]=i;<br>    <span class="hljs-keyword">int</span> t;cin&gt;&gt;t;<br>    <span class="hljs-keyword">while</span>(t--)&#123;<br>        <span class="hljs-keyword">int</span> n,k;<br>        cin&gt;&gt;n&gt;&gt;k;<br>        <span class="hljs-keyword">if</span>(k*<span class="hljs-number">2</span>&gt;=n)&#123;cout&lt;&lt;<span class="hljs-number">-1</span>&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<span class="hljs-keyword">continue</span>;&#125;<br>        <span class="hljs-keyword">int</span> a=<span class="hljs-number">1</span>,b=n-k+<span class="hljs-number">1</span>;<br>        <span class="hljs-keyword">bool</span> flag=<span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">1</span>;i&lt;=n;i++)&#123;<br>            <span class="hljs-keyword">if</span>(i%<span class="hljs-number">2</span>==<span class="hljs-number">1</span>||b&gt;n)cout&lt;&lt;a++&lt;&lt;<span class="hljs-string">&#x27; &#x27;</span>;<br>            <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(i%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>&amp;&amp;b&lt;=n)cout&lt;&lt;b++&lt;&lt;<span class="hljs-string">&#x27; &#x27;</span>;<br>        &#125;<br>        cout&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<br>    &#125;<br>    <span class="hljs-comment">//SYP</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="B-AND-Sequences（思维-构造-排列组合-AND-amp-与运算）"><a href="#B-AND-Sequences（思维-构造-排列组合-AND-amp-与运算）" class="headerlink" title="B.AND Sequences（思维+构造+排列组合+AND&amp;与运算）"></a>B.AND Sequences（思维+构造+排列组合+AND&amp;与运算）</h1><p>链接: <a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513/problem/B">AND Sequences</a>.<br>题意：输入n和n个整数。将n个整数排列，求good permutations的总数对1e9+7取模。<br>good permutations定义为：<img src="https://img-blog.csdnimg.cn/20210412112529758.png" srcset="/img/loading.gif" lazyload alt="样例"><br>这题比赛的时候想法是记录出现两次以上的数字个数和出现次数，若不存在输出0，否则取两个相同数字作为首尾其它位置排列组合。理由是首尾相同之后一定满足good permutations。<br>最终结果：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><code class="hljs c++">        <span class="hljs-comment">// violet apricity</span><br><span class="hljs-comment">// Do all I can do.Do good to be good.</span><br> <br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;cstring&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;string&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;algorithm&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;vector&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;math.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;map&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;sstream&gt;</span></span><br> <br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> STD using namespace std;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ll long long</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> db double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ldb long double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> IOS std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> MAX 88888888</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> INF 0x3f</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> r0 return 0;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> SYP system(<span class="hljs-meta-string">&quot;pause&quot;</span>);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> endl <span class="hljs-meta-string">&#x27;\n&#x27;</span></span><br> <br>STD<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> maxn=<span class="hljs-number">2e5</span>+<span class="hljs-number">5</span>;<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> mod=<span class="hljs-number">1e9</span>+<span class="hljs-number">7</span>;<br><span class="hljs-keyword">int</span> a[maxn];<br>ll pre[maxn];<br><span class="hljs-keyword">int</span> yes[maxn];<br><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span></span><br><span class="hljs-function"></span>&#123;<br>    pre[<span class="hljs-number">1</span>]=pre[<span class="hljs-number">0</span>]=<span class="hljs-number">1</span>;<br>    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">2</span>;i&lt;maxn;i++)&#123;<br>        pre[i]=((i%mod)*(pre[i<span class="hljs-number">-1</span>]%mod))%mod;<br>    &#125;<br>&#125;<br><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-built_in">init</span>();<br>    <span class="hljs-keyword">int</span> t;cin&gt;&gt;t;<br>    <span class="hljs-keyword">while</span>(t--)&#123;<br>        <span class="hljs-keyword">int</span> n;cin&gt;&gt;n;<br>        <span class="hljs-built_in">memset</span>(yes,<span class="hljs-number">0</span>,<span class="hljs-keyword">sizeof</span> yes);<br>        vector&lt;<span class="hljs-keyword">int</span>&gt;ans;<br>        <span class="hljs-keyword">int</span> ma=<span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">int</span> can=<span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;n;i++)&#123;<br>            cin&gt;&gt;a[i];<br>            yes[a[i]]++;<br>            <span class="hljs-keyword">if</span>(yes[a[i]]==<span class="hljs-number">2</span>)ans.<span class="hljs-built_in">push_back</span>(a[i]),can++;<br>        &#125;<br> <br>        <span class="hljs-comment">//cout&lt;&lt;&quot;debug:&quot;&lt;&lt;can&lt;&lt;&#x27;\n&#x27;;</span><br>        <span class="hljs-comment">//cout&lt;&lt;&quot;debug:&quot;&lt;&lt;pre[1]&lt;&lt;&#x27; &#x27;&lt;&lt;pre[2]&lt;&lt;&#x27; &#x27;&lt;&lt;pre[3]&lt;&lt;&#x27;\n&#x27;;</span><br> <br>        <span class="hljs-keyword">if</span>(can==<span class="hljs-number">0</span>)&#123;cout&lt;&lt;<span class="hljs-number">0</span>&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<span class="hljs-keyword">continue</span>;&#125;<br>        ll res=<span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;can;i++)&#123;<br>            ll p=(yes[ans[i]]%mod*(yes[ans[i]]<span class="hljs-number">-1</span>)%mod)%mod*pre[n<span class="hljs-number">-2</span>]%mod;<br>            <span class="hljs-comment">//cout&lt;&lt;&quot;debug:&quot;&lt;&lt;p&lt;&lt;&#x27;\n&#x27;;</span><br>            res+=p;<br>            res%=mod;<br>        &#125;<br>        cout&lt;&lt;res&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<br>    &#125;<br>    <span class="hljs-comment">//SYP</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>结果是wa了，只能过样例点。<br>分析一下为什么wa了：这里很显然a[1]=a[n]是一个<strong>必要条件</strong>，但事实上它<strong>并不是一个充分条件</strong>。因为除了a[1]=a[n]外还要满足a[1]&amp;x=a[n]&amp;x，x=a[2]&amp;a[3]~a[n-1]。<br>来看看官方题解：<br><img src="https://img-blog.csdnimg.cn/20210412113020714.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MDI4MTg2OQ==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="官方题解"></p>
<p>首先解释一下官方题解的意思。<br>pref(i)=a[1]&amp;a[2]&amp; ~ a[i]，<br>suf(i)=a[i]&amp;a[i+1]&amp; ~ a[n]，<br>我们知道几个数相&amp;只会使结果越来越小，所以pref(2)&lt;=pref(1)=suf(2)&lt;=suf(3)，又由题有pref(1)=suf(3)，所以得出：a[1]=pref(2)=suf(3)。<br>从而对1&lt;=i&lt;=n有pref(i)=a[i]&amp;&amp;suf[i]=a[1]。<br>我这里做出自己的另一种理解：<br>有上述可知，若将中间看作整体，有a[1]&amp;x=a[n]，a[1]=x&amp;a[n]，a[1]=a[n]，那么我们可以再把后两项或前两项看作整体，成为一个n-1项的序列，且我们同样可以得出以上结论，即首尾相等且等于首尾分别与中间&amp;的结果，当我们继续往下推可以得到：a[1]=a[1]&amp;a[2]=a[2]&amp;F(a[3]&amp; ~ a[n])，<br>把左右两边&amp;a[1]得到a[1]&amp;a[1]=a[1]&amp;a[2]&amp;F(a[3]&amp;~a[n])，<br>那么a[1]=a[1]&amp; ~ a[n]的结论就得出来了。<br>也就是说要找的首尾应该是相等的且等于所有数&amp;的结果。<br>那么下面就可以来实现了：<br>首先mp记录每个数出现次数，p=a[1]&amp;a[2]~~a[n]，mul=(n-2)!。<br>其中p为放置在首尾的数，mul为中间数字的全排列。<br>若mp[p]&lt;=2说明没有合题意能放在首尾的数即无解输出0，<br>否则 ans=mp[p]* （mp[p]-1）* mul。<br>前两项相乘表示所有合适的数选出来两个排列在首尾的方案数和，即c(2,cnt)。<br>记得边乘边取模。<br>赛后补题：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><code class="hljs c++">        <span class="hljs-comment">// violet apricity</span><br><span class="hljs-comment">// Do all I can do.Do good to be good.</span><br><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;cstring&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;string&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;algorithm&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;vector&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;math.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;map&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;sstream&gt;</span></span><br><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> STD using namespace std;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ll long long</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> db double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ldb long double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> IOS std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> MAX 88888888</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> INF 0x3f</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> r0 return 0;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> SYP system(<span class="hljs-meta-string">&quot;pause&quot;</span>);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> endl <span class="hljs-meta-string">&#x27;\n&#x27;</span></span><br><br>STD<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> maxn=<span class="hljs-number">2e5</span>+<span class="hljs-number">5</span>;<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> mod=<span class="hljs-number">1e9</span>+<span class="hljs-number">7</span>;<br>ll a[maxn];<br>map&lt;ll,ll&gt;mp;<br><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-keyword">int</span> t;cin&gt;&gt;t;<br>    <span class="hljs-keyword">while</span>(t--)&#123;<br>        mp.<span class="hljs-built_in">clear</span>();<br>        <span class="hljs-keyword">int</span> n;cin&gt;&gt;n;<br>        ll p,mul=<span class="hljs-number">1</span>;<br>        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">1</span>;i&lt;=n;i++)&#123;<br>            cin&gt;&gt;a[i];<br>            mp[a[i]]++;<br>            <span class="hljs-keyword">if</span>(i==<span class="hljs-number">1</span>)p=a[i];<br>            <span class="hljs-keyword">else</span> p&amp;=a[i];<br>            <span class="hljs-keyword">if</span>(i&lt;=n<span class="hljs-number">-2</span>)mul=(mul*i)%mod;<br>        &#125;<br>        <span class="hljs-keyword">if</span>(mp[p]&gt;=<span class="hljs-number">2</span>)&#123;<br>            ll ans=(mp[p]*(mp[p]<span class="hljs-number">-1</span>))%mod;<br>            cout&lt;&lt;ans*mul%mod&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<br>        &#125;<br>        <span class="hljs-keyword">else</span> cout&lt;&lt;<span class="hljs-number">0</span>&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<br>    &#125;<br>    <span class="hljs-comment">//SYP</span><br>    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="C-Add-One（dp-矩阵）"><a href="#C-Add-One（dp-矩阵）" class="headerlink" title="C.Add One（dp+矩阵）"></a>C.Add One（dp+矩阵）</h1><p><a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513/problem/C">https://codeforces.com/contest/1513/problem/C</a><br>链接：<a target="_blank" rel="noopener" href="https://codeforces.com/contest/1513/problem/C">Add One</a><br>题意：t组样例，每组给出两个整数n，m。对n操作m次输出最终n的长度对1e9+7取模。<br>操作指：n每一个十进制位的数字加1。eg：1912–&gt;21023。<br>这题比赛时来不及想，不过大概率也做不出来。<br>还是先上官方题解：<br><img src="https://img-blog.csdnimg.cn/20210412125428215.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MDI4MTg2OQ==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>考虑一位数如何加1会变成两位数。<br>对于n=10，操作k次，设dp[i]==操作i次后n长度：<br>0&lt;=k&lt;=8：dp[k]==2;<br>k=9:   dp[k]==3;<br>k&gt;=10:  dp[k]=dp[k-9]+dp[k-10]<br>那么我们可以先预处理一下。<br>最后结果就是：<br><img src="https://img-blog.csdnimg.cn/20210412130303495.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>也就是遍历每一位数设为x，若m+x&lt;10 ans+=1；否则ans+=dp[m+x-10]。<br>记得取模。数据很多所以得IOS关同步。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs c++">        <span class="hljs-comment">// violet apricity</span><br><span class="hljs-comment">// Do all I can do.Do good to be good.</span><br><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;cstring&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;string&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;algorithm&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;vector&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;math.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;map&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;sstream&gt;</span></span><br><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> STD using namespace std;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ll long long</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> db double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> ldb long double</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> IOS std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> MAX 88888888</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> INF 0x3f</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> r0 return 0;</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> SYP system(<span class="hljs-meta-string">&quot;pause&quot;</span>);</span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> endl <span class="hljs-meta-string">&#x27;\n&#x27;</span></span><br><br>STD<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> maxn=<span class="hljs-number">2e5</span>+<span class="hljs-number">5</span>;<br><span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> mod=<span class="hljs-number">1e9</span>+<span class="hljs-number">7</span>;<br><span class="hljs-keyword">int</span> dp[maxn];<br><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span><br><span class="hljs-function"></span>&#123;<br>    IOS<br>    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">9</span>;i++)dp[i]=<span class="hljs-number">2</span>;<br>    dp[<span class="hljs-number">9</span>]=<span class="hljs-number">3</span>;<br>    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">10</span>;i&lt;maxn;i++)dp[i]=(dp[i<span class="hljs-number">-9</span>]+dp[i<span class="hljs-number">-10</span>])%mod;<br>    <span class="hljs-keyword">int</span> t;cin&gt;&gt;t;<br>    <span class="hljs-keyword">while</span>(t--)&#123;<br>        <span class="hljs-keyword">int</span> n,m;<br>        cin&gt;&gt;n&gt;&gt;m;<br>        <span class="hljs-keyword">int</span> ans=<span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">while</span>(n)&#123;<br>            <span class="hljs-keyword">int</span> x=n%<span class="hljs-number">10</span>;<br>            ans+=((x+m&lt;<span class="hljs-number">10</span>)?<span class="hljs-number">1</span>:dp[x+m<span class="hljs-number">-10</span>]);<br>            ans%=mod;n/=<span class="hljs-number">10</span>;<br>        &#125;<br>        cout&lt;&lt;ans&lt;&lt;<span class="hljs-string">&#x27;\n&#x27;</span>;<br>    &#125;<br>    SYP<br>    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>那么就到这了，再往下DEF不会了。</p>
<p>√落幕&gt;-&lt;</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/ACM/">ACM</a>
                    
                      <a class="hover-with-bg" href="/tags/codeforces/">codeforces</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/04/16/Educational-Codeforces-Round-107-Rated-for-Div-2/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">ECFR107(Div.2)2021.04.13</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/04/14/How-to-creat-a-blog-using-hexo/">
                        <span class="hidden-mobile">如何使用Hexo搭建一个自己的静态博客</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.0/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js" ></script>






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "/local-search.xml";
      $('#local-search-input').on('click', function() {
        searchFunc(path, 'local-search-input', 'local-search-result');
      });
      $('#modalSearch').on('shown.bs.modal', function() {
        $('#local-search-input').focus();
      });
    })()
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
